import api from '../service/api'

export const MUTATION_TYPE_GETMENULIST = 'getMenuList'
export const MUTATION_TYPE_QUERYBILLLIST = 'queryBillList'
export const MUTATION_TYPE_ADDBILL = 'addBill'
export const MUTATION_TYPE_QUERYDDWLIST = 'queryDDWList'

export default {
  namespaced: true,
  state: {
    menuList: []
  },
  getters: {},
  mutations: {
    [MUTATION_TYPE_GETMENULIST]: (state, view) => {
      api.getMenuList({
        callback: function (response) {
          if (response && response.status === 200) {
            const {code, msg, data} = response.data
            if (code === '0') {
              console.log(data.menuList)
              state.menuList = data.menuList
            } else {
              alert(msg)
            }
          }
        }
      })
    },
    [MUTATION_TYPE_QUERYBILLLIST]: (state, {payload, callback}) => {
      api.queryBillList({
        payload: payload,
        callback: callback
      })
    },
    [MUTATION_TYPE_ADDBILL]: (state, {payload, callback}) => {
      api.addBill({
        payload: payload,
        callback: callback
      })
    },
    [MUTATION_TYPE_QUERYDDWLIST]: (state, {payload, callback}) => {
      api.queryDDWList({
        payload: payload,
        callback: callback
      })
    }
  },
  actions: {}
}
